Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Local macro not working | dataex attached

    I am defining a couple of variables as below to be a local macro. But Stata 17 is not recognizing 'cllpred' as a local macro. What am I doing wrong?

    Tried:

    local cllpred cllcd38f cllzap70
    display cllpred
    cllpred not found

    -------------------------------------------------------------------------------------------------------------------------------------

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(cllcd38f cllzap70)
    0 0
    1 1
    0 1
    . .
    . .
    1 0
    0 0
    0 .
    1 1
    . .
    . .
    . .
    1 1
    . .
    0 1
    . .
    . .
    . .
    1 1
    . 0
    . .
    . .
    1 1
    1 1
    1 .
    1 1
    1 .
    0 .
    0 1
    0 .
    . .
    . .
    . .
    1 0
    1 1
    . .
    . .
    1 1
    1 0
    . .
    1 .
    0 1
    . .
    0 1
    . 1
    . .
    . 1
    0 .
    . .
    1 1
    . .
    1 .
    1 .
    1 .
    . .
    1 .
    0 .
    . .
    1 .
    . .
    . .
    . .
    1 .
    1 .
    0 .
    1 .
    . .
    . .
    1 .
    0 .
    . .
    . .
    . .
    . .
    . .
    . .
    0 1
    . .
    0 1
    . .
    . .
    . .
    . .
    . .
    . .
    . .
    . 1
    0 1
    1 1
    1 1
    0 1
    1 .
    . .
    . .
    0 .
    0 .
    1 1
    0 0
    . .
    0 0
    end
    label values cllzap70 posneglab
    label values cllcd38f posneglab
    label def posneglab 0 "Negative", modify
    label def posneglab 1 "Positive", modify

  • #2
    Code:
    di "`cllppred'"
    There are two pitfalls here side by side.

    cllppred without single quotes to Stata should be the name of a variable or scalar. No such entity is known to Stata, hence your error message.

    Code:
    display `cllpred'
    would be a step in the right direction, but Stata would evaluate first seeing the variable names inside and then showing their values in observation 1. Not what you want, presumably.

    So, you need to specify the double quotes to insist on seeing the contents of the macro, not an evaluation thereof.

    There is no question here of a local macro "not working". You created a local macro, but you never referred to it.
    Last edited by Nick Cox; 23 Jan 2022, 11:26.

    Comment


    • #3
      Yes. That worked!! Your explanation makes total sense.

      Comment

      Working...
      X